﻿// 页面加载时，异步获取上方表格内容
function GetProblemDisposeData1() {
    if ($('#hidCurrentPage').val() >= $('#hidPageCount').val()) {
        $('#hidCurrentPage').val('1');
    } else {
        $('#hidCurrentPage').val(Number($('#hidCurrentPage').val()) + 1);
    }
    //var isCurrentFactory = '1';
    //if ($("#checkIsCurrentFactory").get(0).checked==false) {//不勾选时表示查看所有分厂
    //    isCurrentFactory = '0';
    //}
    //alert($("#checkIsCurrentFactory").get(0).checked)
    //alert(isCurrentFactory)
    //alert($("#checkIsCurrentFactory").get(0).checked?'1':'0')
    $.ajax({
        type: "GET",
        contentType: "application/x-www-form-urlencoded",
        url: "KanbanHandler.ashx/ProcessRequest?type=ProductionProblemDispose1",
        data: {
            "factoryid": factoryid,
            "currentPage": Number($('#hidCurrentPage').val()),
            "pageSize": pageSize,
            "IsCurrentFactory": $("#checkIsCurrentFactory").get(0).checked ? '1' : '0'
        },
        dataType: "text",
        //cashe: false,
        cache: false,
        success: function (data) {
            var obj = JSON.parse(data);
            var $table = $("#grid");
            $table.empty(); //清空table

            // 生成表头
            var $tr = $("<tr style='line-height:40px;color:#ffff1d; font-size:22px'></tr>");
            $tr.append("<th>问题描述</th>");
            $tr.append("<th>问题类型</th>");
            $tr.append("<th>责任单位</th>");
            $tr.append("<th>责任人</th>");
            $tr.append("<th>实际处理人</th>");
            $tr.append("<th>创建人</th>");
            $tr.append("<th>状态</th>");
            $tr.append("<th>需求程度</th>");
            $tr.append("<th>超期时间(小时)</th>");
            $tr.appendTo("#grid");

            // 生成表格内容
            for (var i = 0; i < obj.arr.length; i++) {
                var trTemp = $("<tr></tr>");
                //问题描述
                if (obj.arr[i]["problemdetails"] !== null) {
                    if (obj.arr[i]["problemdetails"].length > 50) {
                        trTemp.append("<td style='cursor: pointer;' title='" + obj.arr[i]["problemdetails"] + "'>" + obj.arr[i]["problemdetails"].substring(0, 10) + "...</td>");
                    } else {
                        trTemp.append("<td style='cursor: pointer;' title='" + obj.arr[i]["problemdetails"] + "'>" + obj.arr[i]["problemdetails"] + "</td>");
                    }
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                };
                // 问题类型
                if (obj.arr[i]["problemtypename"] != null) {
                    trTemp.append("<td>" + obj.arr[i]["problemtypename"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }

                //责任单位
                if (obj.arr[i]["factoryname"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["factoryname"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }
                // 责任人
                if (obj.arr[i]["toName"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["toName"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }
                //实际处理人
                if (obj.arr[i]["disposeName"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["disposeName"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }
                //创建人
                if (obj.arr[i]["submitName"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["submitName"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }
                //状态
                if (obj.arr[i]["problemStatus"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["problemStatus"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }

                //需求程度
                if (obj.arr[i]["DemandDegree"] !== null) {
                    trTemp.append("<td>" + obj.arr[i]["DemandDegree"] + "</td>");
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                }

                //超期时间
                if (obj.arr[i]["OverdueTime"] !== null) {

                    if (obj.arr[i]["OverdueTime"] == "未超期") {
                        trTemp.append("<td style='color:#fff'>" + obj.arr[i]["OverdueTime"] + "</td>");
                    } else {
                        trTemp.append("<td style='background-color:red;color:#fff'>" + obj.arr[i]["OverdueTime"] + "</td>");
                    }
                } else {
                    trTemp.append("<td>&nbsp;</td>");
                };

                trTemp.appendTo("#grid");
            };

            if (obj.arr.length < pageSize) {
                for (var i = 0; i < pageSize - obj.arr.length; i++) {
                    var trTemp = $("<tr></tr>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.append("<td>&nbsp;</td>");
                    trTemp.appendTo("#grid");
                };
            };
            // 表格隔行渐变
            //for (var i = 0; i < pageSize + 1; i += 2) {
            //    //$("#grid tbody").find("tr").eq(i).css({ "backgroundColor": "#f9f9f9" });
            //    $("#grid tbody").find("tr").eq(i).css({ "line-height": "45px" });
            //};
            $('#hidCurrentPage').val(Number($('#hidCurrentPage').val()) + 1);
            //currentPage++;
            $('#hidPageCount').val(obj.pageNum); // 总页数
        }
    });
};
function GetProblemDisposeData2() {
    var isCurrentFactory = '1';
    if (!$("#checkIsCurrentFactory").get(0).checked) {
        isCurrentFactory = '0';
    }
    $.ajax({
        type: "GET",
        url: "KanbanHandler.ashx/ProcessRequest?type=ProductionProblemDispose2",
        data: {
            "factoryid": factoryid,
            "currentPage": Number($('#hidCurrentPage').val()),
            "pageSize": pageSize,
            "IsCurrentFactory": isCurrentFactory
        },
        dataType: "text",
        //cashe: false,
        cache: false,
        success: function (data) {
            var obj = JSON.parse(data);
            //完工率
            var FinishRate = document.getElementById("FinishRate");
            FinishRate.innerHTML = "&nbsp;";
            //回复率
            var ReplayRate = document.getElementById("ReplayRate");
            ReplayRate.innerHTML = "&nbsp;";
            //超期率
            var OverdueRate = document.getElementById("OverdueRate");
            OverdueRate.innerHTML = "&nbsp;";
            if (obj.arr.length > 0) {
                if (obj.arr[0]["FinishRate"] !== null) {
                    FinishRate.innerHTML = obj.arr[0]["FinishRate"];
                }

                if (obj.arr[0]["ReplayRate"] !== null) {
                    ReplayRate.innerHTML = obj.arr[0]["ReplayRate"];
                }

                if (obj.arr[0]["OverdueRate"] !== null) {
                    OverdueRate.innerHTML = obj.arr[0]["OverdueRate"];
                }
            }
        }
    });
};
function getProblemLook() {
    GetProblemDisposeData1();
    GetProblemDisposeData2();
};